// Copyright 2008 David Mitchell
// Released under the MIT License

using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Drawing;
using NSDuctTape;

namespace SpeakLine
{
	public class StringContainer: NotifyPropertyChangingBase
	{
		public StringContainer()
		{
			_value = string.Empty;
		}
		
		public StringContainer(string value)
		{
			_value = value;
		}
		
		public string Value
		{
			get { return _value; }
			set
			{
				using (ChangeProperties("Value"))
					_value = value;
			}
		}
	
		string _value;
	}

	public class Model : NotifyPropertyChangingBase
	{
		public Model()
		{
			_line = string.Empty;
			_color = Color.Green;
			_speechSynthesizer = new Instance("NSSpeechSynthesizer");
			_speechSynthesizer.SendMessage("setDelegate:", this);
			
			_list = new List<string>();
			_list.Add(new StringContainer("foo").Value);
			_list.Add(new StringContainer("bar").Value);
			_list.Add(new StringContainer("baz").Value);
		}
		
		public string Line
		{
			get { return _line; }
			set
			{
				if (value == null)
					value = string.Empty;
				using (ChangeProperties("Line"))
					_line = value;
			}
		}
		
		public Color Color
		{
			get
			{
				return _color;
			}
			set
			{
				using (ChangeProperties("Color"))
					_color = value;
			}
		}
		
		public bool IsSpeaking
		{
			get { return _isSpeaking; }
			private set
			{
				using (ChangeProperties("IsSpeaking"))
					_isSpeaking = value;
			}
		}
		
		public List<string> List
		{
			get { return _list; }
		}
		
		public void SpeakLine()
		{
			_speechSynthesizer.SendMessage("startSpeakingString:", _line);
			IsSpeaking = true;
		}
		
		public void StopSpeaking()
		{
			_speechSynthesizer.SendMessage("stopSpeaking");
		}
		
		[ObjectiveCName("speechSynthesizer:didFinishSpeaking:")]
		public void OnFinishedSpeaking(Instance speechSynthesizer, bool finishedNormally)
		{
			IsSpeaking = false;
		}
		
		Instance _speechSynthesizer;
		bool _isSpeaking;
		Color _color;
		string _line;
		
		List<string> _list;
	}
}
